﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace WellDone
{
    public partial class RestoreRoleDialog : ChildWindow
    {
        public AddRoleDialog addRoleDialog;

        public RestoreRoleDialog()
        {
            InitializeComponent();
        }

        public async void loadTitles()
        {
            this.IsEnabled = false;
            await Globals.db.GetRoleObjects("Active=0 order by Title");
            foreach (ServiceReferenceOpenRPOS.Role role in Globals.db.RoleRecords)
            {
                cmbRoleTitle.Items.Add(role.col_Title);
            }
            cmbRoleTitle.SelectedIndex = 0;
            this.IsEnabled = true;
        }

        private async void btnOK_Click(object sender, RoutedEventArgs e)
        {
            this.IsEnabled = false;
            // Set the selected role to "active"
            await Globals.db.GetRoleObjects("Title='" + cmbRoleTitle.SelectedValue.ToString() + "'");
            Globals.db.RoleRecords[0].bFilterActive = true;
            Globals.db.RoleRecords[0].col_Active = true;
            await Globals.db.UpdateRoleObject(Globals.db.RoleRecords[0]);
            addRoleDialog.strSelectedValue = cmbRoleTitle.SelectedValue.ToString();
            await addRoleDialog.loadRoles();
            this.DialogResult = true;
            this.IsEnabled = true;
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            addRoleDialog.IsEnabled = true;
            this.DialogResult = false;
        }

    }
}

